// ml:run = $bin < input
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
using namespace std;
struct node{
    int a, b, c, v;
    node (){ }
    node (int a, int b, int c, int v):a(a), b(b), c(c), v(v) {}
    bool operator<(const node &A)const{
        if (a==A.a){
            if (b==A.b)
                return c<A.c;
            return b<A.b;
        }
        return a<A.a;
    }
}p[100010];
int n, m, cnt;
int mxA[100010], A[100010][2], B[100010][3], val[100010];
int c[1010][1010], ss[1010][1010];
int low(int x){
    return x & -x;
}
int sum(int x, int y){
    int res=0;
    for (int i=x;i>0;i-=low(i))
        for (int j=y;j>0;j-=low(j))
            res+=c[i][j];
    return res;
}
void modify(int x, int y, int d){
    for (int i=x;i<=1000;i+=low(i))
        for (int j=y;j<=1000;j+=low(j))
            c[i][j]+=d;
}
int main()
{
    int t;
    scanf("%d", &t);
    for (int TT=1;TT<=t;TT++){
        cnt=0;
        memset(mxA, -1, sizeof(mxA));
        memset(ss, 0, sizeof(ss));
        memset(val, 0, sizeof(val));
        scanf("%d%d", &n, &m);
        for (int i=0;i<n;i++)
            scanf("%d%d", &A[i][0], &A[i][1]);
        for (int i=0;i<m;i++)
            scanf("%d%d%d", &B[i][0], &B[i][1], &B[i][2]);
        for (int i=0;i<n;i++){
            if (mxA[A[i][1]]<A[i][0]){
                mxA[A[i][1]]=A[i][0];
                val[A[i][1]]=1;
            }
            else if (mxA[A[i][1]]==A[i][0])
                val[A[i][1]]++;
        }
        for (int i=0;i<m;i++)
            if (mxA[B[i][2]]!=-1){
                p[cnt++]=node(mxA[B[i][2]], B[i][0], B[i][1], val[B[i][2]]);
            }
        sort(p, p+cnt);
        int N=0;
        for (int i=1;i<cnt;i++)
            if (p[i].a==p[i-1].a && p[i].b==p[i-1].b && p[i].c==p[i-1].c)
                p[N].v+=p[i].v;
            else{
                p[++N]=p[i];
            }
        cnt=N+1;
        //for (int i=0;i<cnt;i++) printf("%d %d %d %d\n", p[i].a, p[i].b, p[i].c, p[i].v);
        memset(c, 0, sizeof(c));
        int ans=0;
        //printf("-------\n");
        for (int i=cnt-1;i>=0;i--){
            if (sum(1000, 1000)-sum(1000, p[i].c-1)-sum(p[i].b-1, 1000)+sum(p[i].b-1, p[i].c-1)==0){
                //printf("%d %d %d %d\n", p[i].a, p[i].b, p[i].c, p[i].v);
                ans+=p[i].v;
            }
            modify(p[i].b, p[i].c, 1);
            ss[p[i].b][p[i].c]+=p[i].v;
        }
        printf("Case #%d: %d\n", TT, ans);
    }
    return 0;
}

